package com.example.xwweibo.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.example.xw.common.entity.Comment;
import com.example.xw.common.entity.User;
import com.example.xw.common.service.CommentService;
import com.example.xw.common.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

@RestController
public class CommentApi {

    @Autowired
    @Qualifier("myCommentServiceImpl")
    private CommentService commentService;

    @PostMapping("/api/comment/add")
    public Result<Comment> addComment(int wbid, String content, @SessionAttribute("cur_user") User user){
        System.out.println(wbid+" "+content);
        return commentService.addComment(wbid,content,user.getLoginname());
    }

    @RequestMapping("/api/comment/list")
    public Result<Page<Comment>> shoListByWeibo(String userloginname, int pagenum, int pagesize){
        return commentService.showListByUser(userloginname,pagenum,pagesize,1);
    }

    @RequestMapping("/api/comment/showlistbyWeibo")
    public Result<Page<Comment>> showListByWeibo(int wbid, int pagenum, int pagesize){
        return commentService.showListByWeibo(wbid,pagenum,pagesize,1);
    }
}
